#!/bin/bash

# Runs an exhaustive fuzz test on all known languages. 
# This might take a while to run

# this lists all the language shortcodes by way of the supported HTML table.
# It's magic.
langs=`php ../../supported.php | sed "s/<tr>/$1\n/g" | awk -F'<td>' '{print $4}' | awk '{print $1}' | sed "s/[,<].*//"`

status=0

logdir="$(dirname $0)/../log/"

echo "Running tests..."
for l in $langs
do
  echo -n "    $l..."
  log="$logdir/fuzz_$l";
  size="10M";
  # BNF is slow and will often flag false positives for 10M
  if [ "$l" == "bnf" ]; then
    size="1M";
  fi
  php fuzz.php --time-limit 600 --size $size $l &> "$log"
  s=$?
  if [ "$s" -ne "0" ]; then
    status=$s
    printf "\033[91mFAILED\033[0m. Log written to $log\n"
  else
    printf "\033[92mOK\033[0m\n"
  fi
done

if [ "$status" -ne "0" ]; then
  echo "Some tests failed, logs were written"
else
  echo "Tests passed"
fi
exit $status

